using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace LevelGenerator
{
    public class Room
    {
        private Rectangle boundary;
        private int mBoundary;
        private int outlineScale = 2;
        private int borderSize = 3;


        public Rectangle Boundary
        {
            get { return boundary; }
        }


        public Room(Rectangle minBoundary, Rectangle maxBoundary)
        {
            Random r = new Random();
            int width = r.Next(minBoundary.Width, maxBoundary.Width);
            int height = r.Next(minBoundary.Height, maxBoundary.Height);
            int x = r.Next(minBoundary.X, maxBoundary.X - width);
            int y = r.Next(minBoundary.Y, maxBoundary.Y - height);

            if (maxBoundary.Width > maxBoundary.Height)
                mBoundary = maxBoundary.Width;
            else
                mBoundary = maxBoundary.Height;

            boundary = new Rectangle(x, y, width, height);
        }

        public Rectangle ReturnBoundary()
        {
            return boundary;
        }
        public Rectangle ReturnOutlineBoundary()
        {
            Rectangle rec = boundary;
            rec.Width += outlineScale * 2 * mBoundary;
            rec.Height += outlineScale * 2 * mBoundary;
            rec.X -= outlineScale * mBoundary;
            rec.Y -= outlineScale * mBoundary;

            return rec;
        }

        public void Draw(SpriteBatch spriteBatch, GraphicsDevice gDevice)
        {
            spriteBatch.Begin();
            //Draw Border
            DrawRectangle(new Rectangle(boundary.X - borderSize,
                                        boundary.Y - borderSize,
                                        boundary.Width + borderSize * 2,
                                        boundary.Height + borderSize * 2),
                          gDevice,
                          spriteBatch,
                          Color.Black);
            //Draw Room
            DrawRectangle(boundary, gDevice, spriteBatch, Color.Gray);
            spriteBatch.End();

        }

        private void DrawRectangle(Rectangle pos, GraphicsDevice gDevice, SpriteBatch spriteBatch, Color color)
        {
            var rect = new Texture2D(gDevice, 1, 1);
            rect.SetData(new[] { color });
            spriteBatch.Draw(rect, pos, color);
        }
    }
}
